package com.java;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 四大函数式接口
 * @author jingjintao
 * @date 2021/10/27 - 22:44
 **/
public class FourFunctionDemo {

    public static void main(String[] args) {

        /*Function<String, Integer> function = new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return null;
            }
        };*/
        Function<String, Integer> function = s -> {return s.length();};
        System.out.println(function.apply("abc"));

        /*Predicate<String> predicate = new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return false;
            }
        };*/
        Predicate<String> predicate = s -> {return s.isEmpty();};
        System.out.println(predicate.test(" "));

        /*Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {

            }
        };*/
        Consumer<String> consumer = s -> {
            System.out.println(s);
        };
        consumer.accept("asd");

        /*Supplier<String> supplier = new Supplier<String>() {
            @Override
            public String get() {
                return null;
            }
        };*/
        Supplier<String> supplier = () -> {return "1024";};
        System.out.println(supplier.get());
    }
}
